#include <iostream>
#include <vector>

using namespace std;

int n = 0;
vector<int> path;
bool check[9];
void dfs(int pos)
{
    if (path.size() == n)
    {
        for (auto& num : path)
        {
            cout << "    " << num;
        }
        cout << endl;
    }

    for (int i = 1; i <= n; i++)
    {
        if (!check[i])
        {
            path.push_back(i);
            check[i] = true;
            dfs(pos + 1);
            path.pop_back();
            check[i] = false;
        }
    }
}

int main()
{
    cin >> n;
    for (int i = 1; i <= n; i++)
    {
        check[i] = true;
        path.push_back(i);
        dfs(1);
        path.pop_back();
        check[i] = false;

    }
    return 0;
}